<?php

namespace app\index\controller;

use app\common\model\Klass;
use app\common\model\Student;

//引用Controller类
use think\Controller;

//请求类
use think\Request;


class StudentController extends IndexController
{
//学生列表
    public function index()
    {
        //获取所有学生，进行分页
        $students = Student::paginate();
        $this->assign('students', $students);
        return $this->fetch();
    }

    //编辑学生信息
    public function edit()
    {
        $id = Request::instance()->param('id/d');

        //判断是否存在当前记录
        if (is_null($Student = Student::get($id))) {
            return $this->error('未找到id为：' . $id . '的记录');
        }

        //取出班级列表
        $klasses = Klass::all();
        $this->assign('klasses', $klasses);

        $this->assign('Student', $Student);
        return $this->fetch();
    }

    //
}
